package com.cn.barcode;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.ProgressBar;

public class RpsInfo extends Activity {
	private String result = null;
	private String[] results;
	private ListView textList;
	private Thread datasThread;
	private String textSize;
	private ProgressBar inforProgressBar;
	private String url;
	private ArrayList<String> mArrayList = new ArrayList<String>();
	private static final String URL = "http://200.200.200.9:8015/android.aspx";

	private Handler getbynetHandler = new Handler() {
		public void handleMessage(Message msg) {
			if (msg.obj != null) {
				results = (String[]) msg.obj;
				for (int i = 0; i < results.length; i++) {
					mArrayList.add(results[i]);
				}
				inforProgressBar.setVisibility(View.INVISIBLE);
				textList.setAdapter(new MyAdapter(RpsInfo.this,
						android.R.layout.simple_expandable_list_item_1,
						mArrayList));
			}
		}
	};

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.rpsinfo);
		textList = (ListView) findViewById(R.id.textlist);
		inforProgressBar = (ProgressBar) findViewById(R.id.circleProgressBar);
		textList.setDividerHeight(0);
	    textList.setCacheColorHint(000000);
		SharedPreferences prefs = PreferenceManager
				.getDefaultSharedPreferences(this);         
		textSize = prefs.getString("textsize", "10");
		url =prefs.getString("number_edit", "http://200.200.200.9:8015/android.aspx");
		Log.v("ADADADAFAFA", textSize);
		Log.v("DDDDDDDDD", url);
		initDatas();
	}

	private void splitSting(String result) {
		results = result.split("\\|");
	}

	private void initDatas() {
		datasThread = new Thread(new DatasThread());
		datasThread.start();
	}

	class DatasThread implements Runnable {
		@Override
		public void run() {
			while (result == null) {
				Intent intent = getIntent();
				result = intent.getStringExtra("resultString");
				String getresult = WebServiceManager.getInstance()
						.getDataByGet(url, result, "123456");
				splitSting(getresult);
				Message message = getbynetHandler.obtainMessage();
				message.obj = results;
				if (results != null) {
					getbynetHandler.sendMessage(message);
				}
			}
		}
	}
}
